package com.enqualcomm.kids.activities;

import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.enqualcomm.kids.R;
import com.enqualcomm.kids.base.BaseActivity;
import com.enqualcomm.kids.component.MyApplication;
import com.enqualcomm.kids.config.userdefault.AppDefault;
import com.enqualcomm.kids.config.userdefault.UserDefault;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;

import common.utils.BufferedSharedPreferences;

/**
 * Created by Sunzhigang on 2016/3/22.
 */
@EActivity(R.layout.activity_gesture_control)
public class GestureLockControlActivity extends BaseActivity {
    private UserDefault userDefault;
    private boolean isSetGestureLock;
    private boolean isOpenGestureLock;

    private BufferedSharedPreferences sp;

    @ViewById(R.id.alarm_checkbox_switch)
    CheckBox alarm_checkbox_switch;
    @ViewById(R.id.gesture_control_rl)
    RelativeLayout gesture_control_rl;
    @ViewById(R.id.change_gesture_ll)
    LinearLayout change_gesture_ll;
    @ViewById(R.id.create_gesture_lock_rl)
    RelativeLayout create_gesture_lock_rl;

    @AfterViews
    void setupView() {
        userDefault = new UserDefault(new AppDefault().getUserid());

        isSetGestureLock = userDefault.isSetGestureLock();
        isOpenGestureLock =userDefault.isOpenGestureLock();

        initGestureSwitch();

        if (!isSetGestureLock) {
            alarm_checkbox_switch.setVisibility(View.GONE);
            create_gesture_lock_rl.setVisibility(View.VISIBLE);
        }

        if (isOpenGestureLock) {
            alarm_checkbox_switch.setChecked(true);
        }
    }

    private void initGestureSwitch() {
        alarm_checkbox_switch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                alarm_checkbox_switch.setChecked(isChecked);
                gesture_control_rl.setSelected(isChecked);
                if (isChecked) {
                    change_gesture_ll.setVisibility(View.VISIBLE);
                    userDefault.setStartOpenGestureLock(true);
                } else {
                    change_gesture_ll.setVisibility(View.GONE);
                    userDefault.setStartOpenGestureLock(false);
                }
            }
        });
    }

    @Click(R.id.change_gesture_ll)
    void changeGsetureLock() {
        startActivity(GestureLockActivity_.class);
        finish();
    }

    @Click(R.id.create_gesture_lock_rl)
    void createGestureLock() {
        startActivity(GestureLockActivity_.class);
        finish();
    }

    @Override
    protected void onResume() {
        super.onResume();

    }
}
